package xginxlog

import (
	"encoding/json"

	"gitee.com/xiaoyutab/xgotool/optional/xlog"
	"gitee.com/xiaoyutab/xgotool/xgin"
	"gitee.com/xiaoyutab/xgotool/xstring"
	"github.com/gin-gonic/gin"
)

// 查看系统日志记录
//
//	GET	/log
func log(c *gin.Context) *xgin.Response {

	type temp_struct struct {
		Type string      `json:"type" form:"type" xml:"type"` //错误类型
		Bigs json.Number `json:"bigs" form:"bigs" xml:"bigs"` //高于该等级的错误记录
	}
	type temp_struct_used struct {
		Type string `json:"type" form:"type" xml:"type"` //
		Bigs int    `json:"bigs" form:"bigs" xml:"bigs"` //
	}
	temp := temp_struct{}
	if err := xgin.Bind(c, &temp); err != nil {
		return xgin.Resp().Error(err)
	}
	// 正式变量赋值
	// 请使用param进行参数验证、变量效验等操作
	param := temp_struct_used{}
	param.Type = temp.Type
	param.Bigs = xstring.JInt(temp.Bigs)
	if param.Type == "" {
		param.Type = "E"
	}
	count, lis, err := xlog.GetLog(param.Type, param.Bigs == 1, c.GetInt("offset"), c.GetInt("limit"))
	if err != nil {
		return xgin.Resp().Error(err)
	}
	return xgin.Resp().Page(c, lis, count)
}
